package com.jandan.ui.server;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.gwtwidgets.server.spring.ServletUtils;

import com.jandan.logic.JWordzFacade;
import com.jandan.ui.client.service.WordCommentService;
import com.jandan.ui.model.WordComment;
import com.jandan.web.front.UserSession;

public class WordCommentServiceImpl implements WordCommentService {
	private JWordzFacade jwordz;

	public void setJwordz(JWordzFacade jwordz) {
		this.jwordz = jwordz;
	}

	public List<WordComment> getWordCommentListByWordID(long wordID) {
		// TODO Auto-generated method stub
		return jwordz.getWordCommentListByWordID(wordID);
	}

	public WordComment addWordComment(WordComment wordComment) {
		// TODO Auto-generated method stub
		HttpSession session = ServletUtils.getRequest().getSession(true);
		UserSession userSession = (UserSession) session
				.getAttribute("userSession");
		if (userSession != null) {
			wordComment.setUserName(userSession.getAccount().getUserName());
			long commentID = jwordz.insertWordComment(wordComment);
			wordComment.setWordCommentID(commentID);
			return wordComment;
		}
		return null;
	}

	public int getWordCommentCountByWordID(long wordID) {
		// TODO Auto-generated method stub
		return jwordz.getWordCommentCountByWordID(wordID);
	}
}
